import requests
from bs4 import BeautifulSoup
res =requests.get(url="https://www.douban.com/group/topic/315744269/?_i=55437891PVwi6f",headers={"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)AppleWebKit/537.36(KHTML,like Gecko)Chrome/95.0.4638.69 Safari/537.36"})
# print(res.text)
soup_object=BeautifulSoup(res.text,"html.parser")
# print(soup_object)
# text01=soup_object.find(name="div",attrs={"class":"rich-content topic-richtext"})
# print(len(text01.text))
comments_object=soup_object.find(name="ul",attrs={"id":"comments"})
comment_object=comments_object.find_all(name="li")
for comment in comment_object:
    ele=comment.find(name="div",attrs={"class":"bg-img-green"})
    name=ele.find(name="a").text
    diqu=ele.find(name="span").text[20:]
    reply=comment.find(name="div",attrs={"class":"markdown"}).text
    recoder=f"{name}({diqu}):{reply}"
    print(recoder)

